//
//  MutiChargeViewController.m
//  aiteshangcheng
//
//  Created by caominglei on 2018/4/24.
//  Copyright © 2018年 aite. All rights reserved.
//

#import "MutiChargeViewController.h"
#import "BackButton.h"
#import "Utility.h"
#import "MutiChargeView.h"
#import "ChargeOnlineView.h"
#import "ChargeSerialView.h"
#import "ChargeCardView.h"
#import "CardChargeView.h"
#import "Network.h"
@interface MutiChargeViewController ()<CardChargeDelegate,SerialDelegate>
{
    BackButton *backbtn;
}
@property (strong, nonatomic) MutiChargeView *mutiView;
@property (strong, nonatomic) ChargeOnlineView *onlineView;
@property (strong, nonatomic) ChargeSerialView *serialView;
@property (strong, nonatomic) ChargeCardView *cardView;
@property (strong, nonatomic) CardChargeView *chargeView;

@end

@implementation MutiChargeViewController
- (CardChargeView *)chargeView
{
    if (!_chargeView) {
        _chargeView = [[CardChargeView alloc] init];
    }
    return _chargeView;
}

- (ChargeCardView *)cardView
{
    if (!_cardView) {
        _cardView = [[ChargeCardView alloc] init];
    }
    return _cardView;
}

- (ChargeSerialView *)serialView
{
    if (!_serialView) {
        _serialView = [[ChargeSerialView alloc] init];
    }
    return _serialView;
}

- (ChargeOnlineView *)onlineView
{
    if (!_onlineView) {
        _onlineView = [[ChargeOnlineView alloc] init];
    }
    return _onlineView;
}

- (MutiChargeView *)mutiView
{
    kWeakSelf(weakSelf);
    if (!_mutiView) {
        _mutiView = [[MutiChargeView alloc] init];
        _mutiView.mutiBtnBlock = ^(NSInteger tag) {
            if (tag == 1420) {
                weakSelf.onlineView.hidden = NO;
                weakSelf.serialView.hidden = YES;
                weakSelf.cardView.hidden = YES;
                weakSelf.chargeView.hidden = YES;

            }else if (tag == 1421) {
                weakSelf.onlineView.hidden = YES;
                weakSelf.serialView.hidden = NO;
                weakSelf.cardView.hidden = YES;
                weakSelf.chargeView.hidden = YES;

            }else if (tag == 1422) {
                weakSelf.onlineView.hidden = YES;
                weakSelf.cardView.hidden = NO;
                weakSelf.serialView.hidden = YES;
                weakSelf.chargeView.hidden = YES;

            }else if (tag == 1423) {
                weakSelf.onlineView.hidden = YES;
                weakSelf.cardView.hidden = YES;
                weakSelf.serialView.hidden = YES;
                weakSelf.chargeView.hidden = NO;            }
        };
    }
    return _mutiView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"在线充值";
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

    
    [self createSubviewsUi];
    [self createSubviewsUiFrame];
}

- (void)createSubviewsUi
{
    [self.view addSubview:self.mutiView];
    [self.view addSubview:self.onlineView];
    self.onlineView.hidden = NO;

    [self.view addSubview:self.serialView];
    self.serialView.hidden = YES;
    self.serialView.delegate = self;
    [self.view addSubview:self.cardView];
    self.cardView.hidden = YES;
    
    [self.view addSubview:self.chargeView];
    self.chargeView.hidden = YES;
    self.chargeView.delegate = self;

}

/**
 

 @param string <#string description#>
 */
- (void)searchSerialWithSearchText:(NSString *)string
{
    
}
#pragma mrak - 充值卡充值

/**
 
 
 key 当前登陆令牌
 rc_sn 平台充值卡号
 */
- (void)cardChargeCommitWithTextString:(NSString *)string
{
    NSString *url = [NSString stringWithFormat:@"%@%@",REMOTEURL,Rechargecard_add];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    dic[@"rc_sn"] = self.chargeView.field.text;

    [Network executePetrechargecard_addTaskWithUrl:url Dict:dic Success:^(id obj) {
        [self setupAlertController:obj[@"datas"][@"error"]];
    } failed:^(id obj) {
        
    }];
}

- (void)setupAlertController:(NSString *)string
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"lovelynotice!", nil) message:NSLocalizedString(string, nil) preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:NSLocalizedString(@"sure", nil) style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:actionConfirm];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)createSubviewsUiFrame
{
    [self.mutiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(40);
        make.top.mas_equalTo(SafeAreaTopHeight);
    }];
    
    [self.onlineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.mutiView.mas_bottom).offset(0);
        make.height.mas_equalTo(600);
    }];
    
    [self.serialView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(400);
        make.top.mas_equalTo(self.mutiView.mas_bottom).offset(10);
    }];
    
    [self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(600);
        make.top.mas_equalTo(self.mutiView.mas_bottom).offset(10);
    }];
    
    [self.chargeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(600);
        make.top.mas_equalTo(self.mutiView.mas_bottom).offset(10);
    }];
}
- (void)popController
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   // [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self setNavgatinBar];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
  //  [self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)setNavgatinBar
{
   
    self.navigationController.navigationBar.hidden = false;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:222.0f/255.0f green:60.0f/255.0f blue:50.0f/255.0f alpha:1];
    
    [self.navigationController.navigationBar setTintColor:UIColor.whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:17],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];

}

@end
